package com.rivulet.dawn.web.controller;

import com.rivulet.dawn.api.model.BraveModel;
import com.rivulet.dawn.api.request.AllDeleteRequest;
import com.rivulet.dawn.api.request.BraveQueryRequest;
import com.rivulet.dawn.api.response.BraveDetailResponse;
import com.rivulet.dawn.api.response.BraveSearchResponse;
import com.rivulet.dawn.api.tools.Page;
import com.rivulet.dawn.api.tools.ResultFul;
import com.rivulet.dawn.service.service.BraveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author: xjc
 * @date: 2022/8/12 17:41
 * @Desc: 用户个人管理
 **/
@Api(value = "用户个人管理", tags = "用户个人管理")
@RestController
@RequestMapping("/brave")
public class BraveController {
    private final BraveService braveService;

    public BraveController(BraveService braveService) {
        this.braveService = braveService;
    }

    @ApiOperation(value = "新增用户")
    @PostMapping("/create")
    public ResultFul<Integer> create(@RequestBody BraveModel braveModel) {
        return ResultFul.OK(braveService.create(braveModel));
    }

    @ApiOperation(value = "修改用户信息")
    @PostMapping("/update")
    public ResultFul<Integer> update(@RequestBody BraveModel braveModel) {
        return ResultFul.OK(braveService.update(braveModel));
    }

    @ApiOperation(value = "删除")
    @PostMapping("/delete")
    public ResultFul<String> delete(@RequestBody AllDeleteRequest request) {
        braveService.delete(request);
        return ResultFul.OK("");
    }

    @ApiOperation(value = "用户详情信息")
    @GetMapping("/detail")
    public ResultFul<BraveDetailResponse> detail(Long id) {
        return ResultFul.OK(braveService.detail(id));
    }

    @ApiOperation(value = "用户列表信息")
    @PostMapping("/search")
    public ResultFul<Page<BraveSearchResponse>> detail(@RequestBody BraveQueryRequest request) {
        return ResultFul.OK(braveService.search(request));
    }
}
